# 二叉树的层次遍历 II
# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def levelOrderBottom(self, root: TreeNode):
        result = []
        level = [root]
        while len(level):
            level_result = []
            tmp = []
            for node in level:
                if node is None:
                    continue
                level_result.append(node.val)
                tmp.append(node.left)
                tmp.append(node.right)
            level = tmp
            if len(level_result):
                result.insert(0, level_result)
        return result



if __name__ == '__main__':
    so = Solution()
    root = TreeNode(1)
    root.left = TreeNode(0)
    root.right = TreeNode(10)
    r = so.levelOrderBottom(root)
    print(r)
